﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace ETOrePriceCalc
{
    public class Mineral : INotifyPropertyChanged
    {
        private string _name;
        private double _price;
        private long _stock;

        /// <summary>
        /// creates a new mineral
        /// </summary>
        /// <param name="name">name of the mineral</param>
        public Mineral(string name)
        {
            _name = name;
            _price = 0;
            _stock = 0;
        }

        /// <summary>
        /// name of the mineral
        /// </summary>
        public string Name
        {
            get { return _name; }
        }

        /// <summary>
        /// price of the mineral (should only be set by the api parser)
        /// </summary>
        public double Price
        {
            get { return _price; }
            set 
            {
                _price = value;
                OnPropertyChanged("StringPrice");
				OnPropertyChanged("StringValue");
            }
        }


        public string StringPrice
        {
            get
            {
                if (_price > 0) return _price.ToString();
                else return "Na";
            }
        }

        /// <summary>
        /// the current stock of this mineral
        /// </summary>
        public long Stock
        {
            get { return _stock; }
            set 
            {
                _stock = value;
                OnPropertyChanged("StringValue");
            }
        }

        /// <summary>
        /// total value of the current stock
        /// </summary>
        public double Value
        {
            get { return _price * _stock; }
        }

        public string StringValue
        {
            get 
            {
                if (_price > 0) return (_price * _stock).ToString();
                else return "Na";
            }
        }

        protected void OnPropertyChanged(string name)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(name));
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
    }
}
